<!--partner_add_order-->
<style>
  .custom-shape img {
    width: 80%;
    margin: .5em 0 1em;
  }
  .custom-shape-radio label {
    display: block;
    margin-bottom: .8em;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
  }
  input[type=radio] {
    margin: 0 0.3em;
  }
  .customer-research input {
    margin-right: .5em;
    width: 50%;
    vertical-align: top;
  }
  .product-info tr {
    border-top: 1px solid# e3e3e3;
  }
  .product-info th {
    background-color: #e8e9eb;
    font-weight: normal;
  }
  .order-checkout {
    margin-top: 2em;
  }
  .customer-list {
    margin-bottom: 2em;
  }
  .customer-list tr {
    border-bottom: 1px solid# e3e3e3;
  }
  .order-comment {
    width: 100%;
    min-height: 100px;
    resize: vertical;
    padding: .2em 0.2em.3em;
    border: 1px solid# ccc;
  }
  .payment-method {
    padding-bottom: 2em;
  }
  .payment-method label input {
    margin-right: .5em;
  }
  .count-num {
    padding: 0.5em;
  }
  .choose-customer-btn.btn {
    margin-left: 1em;
    margin-right: 1em;
    padding-left: 2em;
    padding-right: 2em;
  }

  /*选择商品*/
  .product-detail-select td {
    width: 200px;
  }
  .product-detail-select hr,
  .product-tabs hr {
    height: 0;
    border: none;
    border-bottom: 1px solid# ccc;
    margin: 0;
  }
  .product-tabs ul {
    padding: 0 2em;
  }
  .product-tabs li {
    width: 200px;
    margin: 1px 2em -1px 2em;
  }
  .product-tabs .curs {
    background: #fff;
    color: inherit;
    border: 1px solid #ccc;
    border-bottom: none;
  }
  .preview-img {
    width: 220px;
    padding: 2em 1em 2em 0;
  }
  .view-mode.val {
    display: inline-block;
  }
  .search-area p.error {
    float: left;
    line-height: 2;
    margin-right: 0.3em;
  }
  .cartShow td {
    vertical-align: middle;
  }
  .product-count-wrap .decrease,
  .product-count-wrap .increase {
    display: inline-block;
    width: 25px;
    height: 25px;
    background-color: #3eabb8;
    background-repeat: no-repeat;
    background-position: center center;
    font-size: 0;
    vertical-align: middle;
    cursor: pointer;
  }

  .product-count-wrap .decrease {
    background-image: url();
  }

  .product-count-wrap .increase {
    background-image: url();
  }
  #ID_select{
    padding: 4px 6px;
    border: 1px solid #ccc;
    color: #4a4a4a;
    vertical-align: middle;
    font:inherit;
    margin: 0;
  }

  .paterner-title {
    color: #828282;
    padding: 1em .6em;
    border-bottom: 1px solid #ccc;

  }
  .Garment_size .space{display: inline-block;
    margin: 0 5px;
  }
  .Garment_size .val{display: inline-block;
      margin: 0 5px;
  }
  tr{
    border-collapse: collapse;
    border-spacing: 0;
  }
  td{color: #999;
    padding: .5em .6em;
    vertical-align: top;
  }
  .Garment_size em {
    font-style: normal;
    color: #3eabb8;
  }
  .tab {
    position: relative;
    width: 100%;
    margin: 0 auto;
  }

  .tab-nav {
    width: 100%;
    height: 40px;
    margin-top: 16px;
    background: #e8e9eb;
  }
  .tab-nav a {
    float: left;
    width: calc( 100% /8 );
    height: 40px;
    line-height: 40px;
    text-align: center;
    text-decoration: none;
    color: #999;
  }

  .tab-nav a.current {

    background:#3eabb8;
    color: #fff;
  }

  .tab-con {
    position: relative;

    width:100%;

    height: auto;



    background: #fff;

  }

  .tab-con-item {

    display: none;

    width: 100%;

    height: auto;

    color: #000;

  }


</style>
<div class="heading"><strong><?php echo L('_Order_1');?></strong></div>
<!--选择老用户-->
<div class="customer-list" hidden>
  <div class="partner-title">
    <strong class="pull-left"><?php echo L('Custom_information');?></strong>
    <span class="btn pull-right choose-customer js-choose-customer"><?php echo L('regular_customer');?></span>
  </div>
  <div class="mt1x mb2x align-center customer-research">
    <input type="text" name="customerKeyword" class="js-search">
    <span class="btn js-customer-search"><?php echo L('Search');?></span>
  </div>
  <div id="customerShowDiv"></div>
  <div class="align-center choose-customer-btn">
    <span class="btn mr2x choose-customer-confirm js-confirm"><?php echo L('OK');?></span>
    <span class="btn choose-customer-cancel"><?php echo L('_ORDER_CANCEL_');?></span>
  </div>
</div>
<form action="<?php echo url('cart/checkout_partner'); ?>" method="post" class="order-add-form js-order-add-form">
  <!--填写新用户-->
  <?php include THEMES_PATH . 'partner/partner_create_customer.phtml'; ?>
  <input type="hidden" name="address_id" value="0">
  <!--商品信息-->
  <div class="clearfix partner-title">
    <strong class="pull-left"><?php echo L('Commodity_information');?></strong>
    <div class="pull-right search-area">
      <span class="pull-right btn js-add-product"><?php echo L('Add');?></span>
      <select name="addPid" id="ID_select" placeholder="Product ID">
        <option value="1180">三件套</option>
        <option value="1580">两件套</option>
        <option value="1280">单西</option>
        <option value="1380">裤子</option>
        <option value="1480">马甲</option>
        <option value="1704">衬衫</option>
        <option value="1705">大衣</option>
        <!-- <option value="651">风衣</option> -->
        <option value="1987">羊绒衫</option>
        <option value="653">风衣</option>
        <option value="1869">皮鞋</option>
        <option value="2064">其他产品</option>
      </select>
    </div>
  </div>
  <template class="add-product-wrap">
    <?php include THEMES_PATH . 'partner/partner_product_detail.phtml'; ?>
  </template>
  <!--购物车-->
  <div class="cartShow"></div>
  <!--是否为礼品订单-->
  <div class="item-title">是否为礼品订单：</div>
  <input type="radio" name="is_gift_orders" checked value="0">否  <input type="radio" name="is_gift_orders"  value="1">是
  <!--留言-->
  <div class="item-title">留言</div>
  <textarea class="width-full order-comment" name="remark"></textarea>
  <!-- <div class="item-title">备注</div>
  <textarea class="width-full order-comment" name="client_note"></textarea> -->
  <!--提交订单按钮-->
  <div class="mt1x align-center">
    <input type="hidden" name="dosubmit" value="1">
    <button class="btn order-submit js-submit"><?php echo L('submit');?></button>
  </div>
  <div class="js-show-box"></div>
</form>
<input type="hidden" name="affirmPid" value="0">
<input type="hidden" name="total_number" value="0">
<script>
function customer_res_ajax(customerId, callback) {
  $.ajax({
    type: 'POST',
    url: '/partner/customer_res_ajax',
    data: {'customerid': customerId},
    success: function (result) {
      result = eval('(' + result + ')');
      if (result['status'] != '1') {
        return;
      }
      $('input[name="address_id"]').val(customerId);
      var res = result['data'];
      $.each(res,function(i,v){
          /*Custom information*/
          if(v!=0 && v!=""){
              $("input:text." + i).parents(".custormer_nv_td").show();
          }
          $("input:text." + i).val(v).siblings(".val").text(v);
          if($('select[name="'+ i +'"]').length > 0){
              $('select[name="'+ i +'"]').val(v).siblings(".val").text(v);
          }
          $("select." + i).val(v);
        if(i=="size_measure"){
          $.each(v,function(j,vv){
            $.each(vv['cy'],function(h,vvv){
                if(vvv!=0){
                    $("input[name='size_measure[" + j + "][cy]"+"["+ h +"]").parents("td").show();
                    $("input[name='size_measure[" + j + "][cy]"+"["+ h +"]").val(vvv).siblings(".val").text(vvv);
                }else{
                    $("input[name='size_measure[" + j + "][cy]"+"["+ h +"]").parents("td").hide();
                }

              //$("input:text.size_measure[" + j + "][cy]"+"["+ h +"]" ).val(vvv).siblings(".val").text(vvv);
            });
          });
        }
      });

      /*delivery_cid*/
      $(".delivery_cid").siblings(".val").text($(".delivery_cid option:selected").text());
      /*Somatotype*/
        $("input:radio.shoulder[value=" + res['shoulder'] + "]").attr("checked", true);
      $("input:radio.shoulder[value=" + res['shoulder'] + "]").attr("checked", true);
      $("input:radio.chest_type[value=" + res['chest_type'] + "]").attr("checked", true);
      $("input:radio.posture[value=" + res['posture'] + "]").attr("checked", true);
      $("input:radio.stomach_type[value=" + res['stomach_type'] + "]").attr("checked", true);
      $.each($(".custom-shape .item"),function(){
        var _self = $(this);
        _self.find(".val").text(_self.find("input:radio:checked").parent().text());
      });

      /*视图模式*/
      $(".js-create-customer").addClass("view-mode").removeClass("edit-mode").find(".error").hide();

      cartShow();

      if (typeof callback === 'function') {
        callback();
      }
    }
  });
}

function iframeHtml(url) {
  var iframe = '<iframe runat="server" src="' + url + '" width="100%" height="600" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="yes" allowtransparency="yes"></iframe>';
  return iframe;
}

function showCustomer(page) {
  var keywords = $('input[name="customerKeyword"]').val();
  $.ajax({
    type: 'GET',
    url: '/partner/customer_list_ajax',
    data: {'keywords': keywords, 'p': page},
    success: function (content) {
      $('#customerShowDiv').hide();
      $('#customerShowDiv').html(content).show();
    }
  });
}

function cartShow() {
  var shipping_method_val = $("input[name='shipping_method']:checked").val();
  var payment_method_val = $("input[name='payment_method']:checked").val();
  var delivery_cid = $("#delivery_cid").val();
  $.ajax({
    type: 'GET',
    url: '/partner/cart',
    data: {
      'shipping_method_val': shipping_method_val,
      'payment_method_val': payment_method_val,
      'delivery_cid': delivery_cid
    },
    success: function (content) {
      $('.cartShow').html(content).show();
    }
  });
}

function addProduct() {
  var pid = parseInt($('input[name="affirmPid"]').val());
  if (!isNaN(pid) && pid > 0) {
    return $.ajax({
      type: 'GET',
      url: '/cart/productpost_partner',
      data: {'pid': pid}
    })
    .done(function () {
      cartShow();
    });
  }
}

$(function () {
  cartShow();

  <?php if(intval($addrid)>0):?>
  customer_res_ajax(<?php echo $addrid;?>);
  <?php endif;?>

  /*选择老客户*/
  $(".js-choose-customer").removeClass("hide").on("click", function () {
      $('input[name="customerKeyword"]').val('');
      if ($(".customer-list").is(":hidden")) {
          showCustomer(1);
          $(".customer-list").show();
          $(".create-customer").add($(".create-customer").prev(".partner-title")).hide();

      } else {
          $(".create-customer").add($(".create-customer").prev(".partner-title")).show();
          $(".customer-list").hide();
      }
  });

  $(".choose-customer-btn").on("click", ".btn", function () {
    $(this).closest(".customer-list").find(".js-choose-customer").trigger("click");
  });


  $(".choose-customer-confirm").bind("click", function () {
    var customerId = parseInt($('input:radio[name="customerId"]:checked').val());
    if (customerId > 0) {
      customer_res_ajax(customerId);
    }
  });

  $(".js-customer-search").on("click", function () {
    showCustomer(1);
  });


  /*添加商品*/
  $('.js-add-product').on('click', function() {
    $('input[name="affirmPid"]').val(0);
    var pid = parseInt($('#ID_select').val());
    if (isNaN(pid)) {
      alert('<?php echo L('input_product_id');?>');
      return;
    }

    $.ajax({
      url: '<?php echo url('partner/product_add');?>/pid/' + pid
    })
    .done(function (result) {
      result = eval('(' + result + ')');

      if (result['error'] == '1') {
        $('input[name="affirmPid"]').val(pid);
        addProduct();
      } else if (result['error'] == '2') {
        $(document).popupBox({
          eventType: null,
          quickClose: true,
          button: ['确认', '取消'],
          content: function () {
            $('input[name="affirmPid"]').val(0);
            var pid = parseInt($('#ID_select').val());
            return iframeHtml('<?php echo url('product/rewrite_custom');?>/partner/1/id/' + pid);
          },
          onOk: function () {
            addProduct();
            updateAmount();
          }
        });
      } else {
        alert(result['errstr']);
      }
    });
  });

  /*表单验证*/
  $('.js-order-add-form').validate({
    errorElement: 'p',
    submitHandler: function (form) {
      if ( parseInt($('input[name=total_number]').val()) ) {
        form.submit();
      } else {
        alert('<?php echo L('nothing_in_cart_partner')?>');
        return false;
      }
    },
    errorPlacement: function (error, element) {
      element.after(error);
    }
  });

  $("#delivery_cid").bind('change', function () {
    cartShow();
  });
});
</script>
<script type="text/javascript">

  $(function() {
    $("#tab").rTabs();
    $("#tab2").rTabs({
      bind : 'click'
    });
  })
</script>
<script>


    $.fn.rTabs = function(options){
      //默认值
      var defaultVal = {
        btnClass:'.j-tab-nav',	/*按钮的父级Class*/
        conClass:'.j-tab-con',	/*内容的父级Class*/
        bind:'hover',	/*事件参数 click,hover*/
        animation:'0',	/*动画方向 left,up,fadein,0 为无动画*/
        speed:300, 	/*动画运动速度*/
        delay:200,	/*Tab延迟速度*/
        auto:false,	/*是否开启自动运行 true,false*/
        autoSpeed:0	/*自动运行速度*/
      };

      //全局变量
      var obj = $.extend(defaultVal, options),
          evt = obj.bind,
          btn = $(this).find(obj.btnClass),
          con = $(this).find(obj.conClass),
          anim = obj.animation,
          conWidth = con.width(),
          conHeight = con.height(),
          len = con.children().length,
          sw = len * conWidth,
          sh = len * conHeight,
          i = 0,
          len,t,timer;

      return this.each(function(){

        //判断动画方向
        function judgeAnim(){
          var w = i * conWidth,
              h = i * conHeight;
          btn.children().removeClass('current').eq(i).addClass('current');
          switch(anim){
            case '0':
              con.children().hide().eq(i).show();
              break;
            case 'left':
              con.css({position:'absolute',width:sw}).children().css({float:'left',display:'block'}).end().stop().animate({left:-w},obj.speed);
              break;
            case 'up':
              con.css({position:'absolute',height:sh}).children().css({display:'block'}).end().stop().animate({top:-h},obj.speed);
              break;
            case 'fadein':
              con.children().hide().eq(i).fadeIn();
              break;
          }
        }

        //判断事件类型
        if(evt == "hover"){
          btn.children().hover(function(){
            var j = $(this).index();
            function s(){
              i = j;
              judgeAnim();
            }
            timer=setTimeout(s,obj.delay);
          }, function(){
            clearTimeout(timer);
          })
        }else{
          btn.children().bind(evt,function(){
            i = $(this).index();
            judgeAnim();
          })
        }

        //自动运行
        function startRun(){
          t = setInterval(function(){
            i++;
            if(i>=len){
              switch(anim){
                case 'left':
                  con.stop().css({left:conWidth});
                  break;
                case 'up':
                  con.stop().css({top:conHeight});
              }
              i=0;
            }
            judgeAnim();
          },obj.autoSpeed)
        }

        //如果自动运行开启，调用自动运行函数
        if(obj.auto){
          $(this).hover(function(){
            clearInterval(t);
          },function(){
            startRun();
          })
          startRun();
        }

      })

    }
</script>

